#pragma tabsize 0
#pragma semicolon 1
#pragma newdecls required
#include <sourcemod>
#include <left4dhooks>
#define PLUGIN_VERSION "1.0"

ConVar g_smoker_y, g_smoker_z, g_smoker_qq, g_hCvarDamage3;
float h_smoker_y, h_smoker_z, 	g_fDamage3;
int h_smoker_qq;


public Plugin myinfo =
{
	name = "l4d2_smoker_attacker_jump",
	author = "豆瓣酱な",
	description = "smoker吐舌头击飞玩家.",
	version = PLUGIN_VERSION,
	url = "https://gitee.com/sweet-and-sour-bombs/adfvsdsd"
};


public void OnPluginStart()
{

	g_smoker_qq = CreateConVar("smoker_xy_jump", "1", "是否启用插件?", FCVAR_NOTIFY, true, 0.0, true, 1.0);
	g_smoker_y = CreateConVar("smoker_y_jump", "100.0", "玩家Y轴高度.", FCVAR_NOTIFY, true, 0.0);
	g_smoker_z = CreateConVar("smoker_z_jump", "350.0",   "玩家Z轴击飞高度.", FCVAR_NOTIFY, true, 0.0);
	g_hCvarDamage3 = CreateConVar("l4d_meteor_smoker_damages", "15.0", "smoker吐舌头击飞玩家造成的损害.", FCVAR_NOTIFY, true, 0.0);	
	CreateConVar("l4d2_smoker_attacker_jump_version", PLUGIN_VERSION, "插件版本.", FCVAR_NOTIFY);

	HookConVarChange(g_smoker_qq, eConvarChanged);
	HookConVarChange(g_smoker_y, eConvarChanged);
	HookConVarChange(g_smoker_z, eConvarChanged);
	HookConVarChange(g_hCvarDamage3, eConvarChanged);


	HookEvent("tongue_grab", Event_TongueGrab, EventHookMode_Pre);//舌头控人事件1



	//AutoExecConfig(true, "l4d2_smoker_attacker_jump");
}


public void OnMapStart()
{
	CvarsChanged();
}

public void eConvarChanged(Handle hCvar, const char[] sOldVal, const char[] sNewVal)
{
	CvarsChanged();
}

void CvarsChanged()
{
	h_smoker_qq = g_smoker_qq.IntValue;
	h_smoker_y = g_smoker_y.FloatValue;
	h_smoker_z = g_smoker_z.FloatValue;
	g_fDamage3 = g_hCvarDamage3.FloatValue;	

}


//舌头控人事件
public void Event_TongueGrab(Event event, const char[] name, bool dontBroadcast)
{
	if (h_smoker_qq == 0)
	return;

	int victim = GetClientOfUserId(event.GetInt("victim"));
	int attacker = GetClientOfUserId(event.GetInt("userid"));

    if (IsValidClient(victim))
    {
		if (ValidInfected(attacker))
		{
			int zombieClass = GetEntProp(attacker, Prop_Send, "m_zombieClass");
			if (zombieClass == 1) // 仅处理 Smoker
			{
				// 1. 先施加伤害
				HurtEntity(victim, attacker, g_fDamage3);

				// 2. 击飞玩家
				L4D2_Circle(victim, attacker);

				// 3. 释放玩家（避免解控后伤害被重置）
				L4D_Smoker_ReleaseVictim(victim, attacker);
			}
		}
	}
}

public void L4D2_Circle(int victim, int attacker)
{
    if (IsValidClient(victim) && ValidInfected(attacker))
	{
				float HeadingVector[3], resulting[3], fPos[3];
				GetClientEyeAngles(attacker, HeadingVector);
				GetEntPropVector(victim, Prop_Data, "m_vecVelocity", resulting);

				resulting[0] += Cosine(DegToRad(HeadingVector[1])) * h_smoker_y;
				resulting[1] += Sine(DegToRad(HeadingVector[1])) * h_smoker_y;
				resulting[2] =  h_smoker_z;
				TeleportEntity(victim, NULL_VECTOR, NULL_VECTOR, resulting);
				GetClientAbsOrigin(attacker, fPos);
				L4D_StaggerPlayer(victim, attacker, fPos); // 踉跄  效果
				L4D2_CTerrorPlayer_Fling(victim, attacker, resulting); //击飞效果
	}
}

stock void HurtEntity(int victim, int client, float damage)
{
	SDKHooks_TakeDamage(victim, client, client, damage, DMG_SLASH);
}









bool IsValidClient(int client)
{
	return client > 0 && client <= MaxClients && IsClientInGame(client) && GetClientTeam(client) == 2 && IsPlayerAlive(client);
}

bool ValidInfected(int client)
{
	return client > 0 && client <= MaxClients && IsClientInGame(client) && GetClientTeam(client) == 3 && IsPlayerAlive(client);
}







